/**
 * The Community Project
 * Copyright Team1 Productions
 * 
 * Joshua Amick
 * Stephen Cunningham
 * Thema Davis
 * Tomika Dawson
 * Lucie DeCristofaro
 * 
 * All Rights Reserved.
 */

package com.business;

import java.sql.Timestamp;

import com.dao.AnnouncementDAO;
import com.dao.EventDAO;
import com.dao.UserDAO;
import com.domain.User;
import com.util.PasswordEncoder;

public class PublicManager{
	//Handle to all the DAO's
	protected AnnouncementDAO announcementDAO;
	protected EventDAO eventDAO;
	protected UserDAO userDAO;
	protected PasswordEncoder passEncode;
	
	public void setAnnouncementDAO(AnnouncementDAO announcementDAO) {
		this.announcementDAO = announcementDAO;
	}
	public void setEventDAO(EventDAO eventDAO) {
		this.eventDAO = eventDAO;
	}
	public void setUserDAO(UserDAO userDAO) {
		this.userDAO = userDAO;
	}
	public void setPassEncode(PasswordEncoder passEncode) {
		this.passEncode = passEncode;
	}
	
	//This method logs the user in
	public User loginUser(String username, String password) {
		User user = this.userDAO.getUserByUsername(username);
		if(user!=null){
			String encodedLoginPassword = passEncode.encode(password);
			if(user.getPassword().equals(encodedLoginPassword)){
				Timestamp now = new Timestamp(System.currentTimeMillis());
				user.setLastModDate(now);
				return this.userDAO.save(user);
			}
			else return null;
		}
		else return null;
	}
	
}
